﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Specification_Pattern
{
    /// <summary>
    /// 规格的逻辑加法
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class AndSpecification<T> : CompositeSpecification<T>
    {
        /// <summary>
        /// 加运算左参数
        /// </summary>
        ISpecification<T> leftSpecification;
        /// <summary>
        /// 加运算右参数
        /// </summary>
        ISpecification<T> rightSpecification;
        /// <summary>
        /// 加运算
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        public AndSpecification(ISpecification<T> left, ISpecification<T> right)
        {
            this.leftSpecification = left;
            this.rightSpecification = right;
        }
        /// <summary>
        /// 重新实现自描述
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public override bool IsSatisfiedBy(T o)
        {
            return this.leftSpecification.IsSatisfiedBy(o)
                && this.rightSpecification.IsSatisfiedBy(o);
        }
    }
}
